import { CarType, Question, Subject } from "@/types/practice";
import request from "@/utils/request";

const baseURL = "/train/question";

export type PaperRecord = {
  id: string;
  carType: Question["carType"]; // 车型
  subject: Question["subject"]; // 科目
  duration: number; // 做题时长
  completed: boolean; // 是否完成
  passed: boolean; // 是否通过
  score: number; // 得分
  createTime: number; // 创建时间
};

export type PaperRecordCreateReq = Omit<PaperRecord, "id" | "memberId" | "createTime"> & { paperId: string };

export type AppMemberPaperSummaryRespVO = {
  examCount: number;
  passesCount: number;
};

export const createPaperRecord = (record: PaperRecordCreateReq) =>
  request<Res<boolean>>({
    url: `${baseURL}/create-paper-record`,
    method: "post",
    data: record,
  });

export const getPaperRecordByPaperId = (paperId: string) =>
  request<Res<PaperRecord>>({
    url: `${baseURL}/get-paper-record-by-paper-id`,
    method: "get",
    params: { paperId },
  });

// 获取模考当前信息总汇
export const getMemberPaperSummary = (carType: Question["carType"], subject: Question["subject"]) =>
  request<Res<AppMemberPaperSummaryRespVO>>({
    url: `${baseURL}/get-member-paper-summary`,
    method: "post",
    data: { carType, subject },
  });

// 分页查询当前用户模考信息
export const getMemberPaperRecord = (data: PageParams & { carType: Question["carType"]; subject: Question["subject"] }) =>
  request<Res<PageResult<PaperRecord>>>({
    url: `${baseURL}/page-member-paper-record`,
    method: "post",
    data,
  });
